package desktop_codebehind;

import java.util.ArrayList;
import common.GUIColor;
import desktop_fields.*;

/**
 * Creates all the fields
 * @author Ronnie
 */
public final class FieldFactory {
	// 75% > 40 so increase in capacity is required
	private static ArrayList<DesktopField> fields = new ArrayList<DesktopField>(54);
	
	public static ArrayList<DesktopField> createFieldsFromArrayList(ArrayList<DesktopField> fieldsInArrayList) {
		if(fields.isEmpty()) {
			fields = fieldsInArrayList;
		}
		return fields;
	}
 	public ArrayList<DesktopField> makeTestFields() {
		if(fields.isEmpty()) {
			DesktopField start1 = new Start.Builder().build();
			fields.add(start1);
			
			DesktopField start2 = new Start.Builder()
				.setBgColor(GUIColor.MAGENTA)
				.setFgColor(GUIColor.BLUE)
				.setTitle("Begin")
				.setSubText("Get money")
				.setDescription("Collecting...\nWait for it!")
				.build();
			fields.add(start2);
			
			DesktopField tax1 = new Tax.Builder().build();
			fields.add(tax1);
			
			DesktopField tax2 = new Tax.Builder()
				.setBgColor(GUIColor.GRAY)
				.setFgColor(GUIColor.BLACK)
				.setTitle("Betal skat\nBetal skat\nBetal skat\nBetal skat\nBetal skat")
				.setSubText("2000 kr.")
				.setDescription("Skattefelt")
				.build();
			fields.add(tax2);
			
			DesktopField refuge1 = new Refuge.Builder().build();
			fields.add(refuge1);
			
			DesktopField refuge2 = new Refuge.Builder()
				.setBgColor(GUIColor.YELLOW)
				.setFgColor(GUIColor.BLACK)
				.setTitle("Refuge is here!")
				.setSubText("Get 5000")
				.setDescription("This is a refuge")
				.setPicture("/desktop_resources/buildings/3House.png")
				.build();
			fields.add(refuge2);
			
			DesktopField jail1 = new Jail.Builder().build();
			fields.add(jail1);
			
			DesktopField jail2 = new Jail.Builder()
				.setBgColor(GUIColor.YELLOW)
				.setFgColor(GUIColor.BLACK)
				.setSubText("Go to Jail")
				.setDescription("This is a go to jail field.")
				.setPicture("/desktop_resources/pics/GoToJail.jpg")
				.build();
			fields.add(jail2);
			
			DesktopField chance1 = new Chance.Builder().build();
			fields.add(chance1);
			
			DesktopField chance2 = new Chance.Builder()
				.setBgColor(GUIColor.YELLOW)
				.setFgColor(GUIColor.BLACK)
				// .setTitle("Go To Jail is here!")
				// .setSubText("Go to Jail")
				// .setDescription("This is a go to jail field.")
				.build();
			fields.add(chance2);
			
			DesktopField street1 = new Street.Builder().build();
			fields.add(street1);
			
			DesktopField street2 = new Street.Builder()
				.setBgColor(GUIColor.YELLOW)
				.setFgColor(GUIColor.BLACK)
				.setTitle("Go To Jail is here!")
				.setSubText("Go to Jail")
				.setDescription("This is a go to jail field.")
				.build();
			fields.add(street2);
		}
		return fields;
	}
	
	public ArrayList<DesktopField> makeDefaultFields() {
		if(fields.isEmpty()) {
		fields.add(new Start.Builder().build());
		
		fields.add(new Street.Builder()
			.setTitle("Rødovrevej")
			.setBgColor(new GUIColor(75, 155, 255))
			.setSubText("kr. 1200")
			.setDescription("Rødovrevej")
			.setRent("$ 50")
			.build());
		
		fields.add(new Chance.Builder().build());
		
		fields.add(new Street.Builder()
			.setTitle("Hvidovrevej")
			.setBgColor(new GUIColor(75, 155, 255))
			.setSubText("kr. 1200")
			.setDescription("Hvidovrevej")
			.setRent("kr. 50")
			.build());
		
		fields.add(new Tax.Builder()
			.setTitle("Betal indkomstskat")
			.setSubText("10% el. kr.4000")
			.setDescription("Betal indkomstskat\n10% eller kr. 4000,-")
			.build());
		
		fields.add(new Shipping.Builder()
			.setTitle("Scanlines")
			.setSubText("kr. 4000")
			.setDescription("Scanlines\nHelsingør-Helsingborg")
			.setPicture("default")
			.setRent("kr. 500")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Roskildevej")
			.setBgColor(new GUIColor(255, 110, 10))
			.setSubText("kr. 2000")
			.setDescription("Roskildevej")
			.setRent("kr. 100")
			.build());
		
		fields.add(new Chance.Builder().build());
		
		fields.add(new Street.Builder()
			.setTitle("Valby\nLanggade")
			.setBgColor(new GUIColor(255, 110, 10))
			.setSubText("kr. 2000")
			.setDescription("ValbyLanggade")
			.setRent("kr. 100")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Allégade")
			.setBgColor(new GUIColor(255, 110, 10))
			.setSubText("kr. 2400")
			.setDescription("Allégade")
			.setRent("kr. 150")
			.build());
		
		fields.add(new Jail.Builder()
			.setPicture("default")
			.setSubText("På besøg")
			.setDescription("På besøg i fængslet")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Frederiksberg\nAllé")
			.setBgColor(new GUIColor(152, 204, 50))
			.setSubText("kr. 2800")
			.setDescription("Frederiksberg Allé")
			.setRent("kr. 200")
			.build());
		
		fields.add(new Brewery.Builder()
			.setTitle("Tuborg")
			.setPicture("default")
			.setDescription("Tuborg bryggeri")
			.setRent("100 x terningeslag")
			.setSubText("kr. 3000")
			.setFgColor(GUIColor.WHITE)
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Bülowsvej")
			.setBgColor(new GUIColor(152, 204, 50))
			.setSubText("kr. 2800")
			.setDescription("Bülowsvej")
			.setRent("kr. 200")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Gl. Kongevej")
			.setBgColor(new GUIColor(152, 204, 50))
			.setSubText("kr. 3200")
			.setDescription("Gammel kongevej")
			.setRent("kr. 250")
			.build());
		
		fields.add(new Shipping.Builder()
			.setTitle("Mols-linie")
			.setSubText("kr. 4000")
			.setDescription("Mols-linien\nEn genvej i Danmark")
			.setPicture("default")
			.setRent("kr. 500")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Bernstorffs-\nvej")
			.setBgColor(new GUIColor(153, 153, 153))
			.setSubText("kr. 3600")
			.setDescription("Bernstorffsvej")
			.setRent("kr. 300")
			.build());
		
		fields.add(new Chance.Builder().build());
		
		fields.add(new Street.Builder()
			.setTitle("Hellerupvej")
			.setBgColor(new GUIColor(153, 153, 153))
			.setSubText("kr. 3600")
			.setDescription("Hellerupvej")
			.setRent("kr. 300")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Strandvejen")
			.setBgColor(new GUIColor(153, 153, 153))
			.setSubText("kr. 4000")
			.setDescription("Strandvejen")
			.setRent("kr. 350")
			.build());
		
		fields.add(new Refuge.Builder()
			.setTitle("Parkering")
			.setSubText("Parkering")
			.setDescription("Modtag kr. 5000")
			.setBgColor(new GUIColor(110, 220, 255))
			.setPicture("default")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Trianglen")
			.setBgColor(new GUIColor(255, 0, 0))
			.setSubText("kr. 4400")
			.setDescription("Trianglen")
			.setRent("kr. 350")
			.build());
		
		fields.add(new Chance.Builder().build());
		
		fields.add(new Street.Builder()
			.setTitle("Østerbrogade")
			.setBgColor(new GUIColor(255, 0, 0))
			.setSubText("kr. 4400")
			.setDescription("Østerbrogade")
			.setRent("kr. 350")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Grønningen")
			.setBgColor(new GUIColor(255, 0, 0))
			.setSubText("kr. 4800")
			.setDescription("Grønningen")
			.setRent("kr. 400")
			.build());
		
		fields.add(new Shipping.Builder()
			.setTitle("Scanlines")
			.setSubText("kr. 4000")
			.setDescription("Scanlines\nGedser-Rostock")
			.setPicture("default")
			.setRent("kr. 500")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Bredgade")
			.setBgColor(new GUIColor(255, 255, 255))
			.setSubText("kr. 5200")
			.setDescription("Bredgade")
			.setRent("kr. 450")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Kgs. Nytorv")
			.setBgColor(new GUIColor(255, 255, 255))
			.setSubText("kr. 5200")
			.setDescription("Kongens Nytorv")
			.setRent("kr. 450")
			.build());
		
		fields.add(new Brewery.Builder()
			.setTitle("Carlsberg")
			.setPicture("default")
			.setDescription("Carlsberg bryggeri")
			.setRent("100 x terningeslag")
			.setSubText("kr. 3000")
			.setFgColor(GUIColor.WHITE)
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Østergade")
			.setBgColor(new GUIColor(255, 255, 255))
			.setSubText("kr. 5600")
			.setDescription("Østergade")
			.setRent("kr. 500")
			.build());
		
		fields.add(new Jail.Builder()
			.setPicture("default")
			.setSubText("Gå i fængsel")
			.setDescription("De fængsles\nSlå to ens for at komme ud")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Amagertorv")
			.setBgColor(new GUIColor(255, 255, 50))
			.setSubText("kr. 6000")
			.setDescription("Amagertorv")
			.setRent("kr. 550")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Vimmelskaftet")
			.setBgColor(new GUIColor(255, 255, 50))
			.setSubText("kr. 6000")
			.setDescription("Vimmelskaftet")
			.setRent("kr. 550")
			.build());
		
		fields.add(new Chance.Builder().build());
		
		fields.add(new Street.Builder()
			.setTitle("Nygade")
			.setBgColor(new GUIColor(255, 255, 50))
			.setSubText("kr. 6400")
			.setDescription("Nygade")
			.setRent("kr. 600")
			.build());
		
		fields.add(new Shipping.Builder()
			.setTitle("Scanlines")
			.setSubText("kr. 4000")
			.setDescription("Scanlines\nRødby-Puttgarden")
			.setPicture("default")
			.setRent("kr. 500")
			.build());
		
		fields.add(new Chance.Builder().build());
		
		fields.add(new Street.Builder()
			.setTitle("Frederiks-\nberggade")
			.setBgColor(new GUIColor(150, 60, 150))
			.setFgColor(GUIColor.WHITE)
			.setSubText("kr. 7000")
			.setDescription("Frederiksberggade")
			.setRent("kr. 700")
			.build());
		
		fields.add(new Tax.Builder()
			.setTitle("Ekstra-\nordinær\nstatsskat:")
			.setSubText("kr.2000")
			.setDescription("Betal Ekstraordinærstatsskat\nkr. 2000,-")
			.build());
		
		fields.add(new Street.Builder()
			.setTitle("Rådhus-\npladsen")
			.setBgColor(new GUIColor(150, 60, 150))
			.setFgColor(GUIColor.WHITE)
			.setSubText("kr. 8000")
			.setDescription("Rådhuspladsen")
			.setRent("kr. 1000")
			.build());
		}		
		return fields;
	}
	// public static String path = null;
	// private enum Type {
	// BREWERY, CHANCE, JAIL, REFUGE, SHIPPING, START, STREET, TAX
	// }
	// public static ArrayList<Field> fields = null;
	//
	// private FieldFactory() {
	//
	// }
	//
	// public static void makeFields() {
	// FieldFactory fact = new FieldFactory();
	// if (fields == null || fields.size() == 0) {
	// try {
	// fact.parse();
	// } catch (NumberFormatException e) {
	// System.out.println("NumberFormatException");
	// }
	// }
	// }
	//
	// private boolean parse() {
	// String str = readFile();
	//
	// if (str == null) {
	// return false;
	// }
	//
	// // 75% > 40 so increase in capacity is required
	// fields = new ArrayList<Field>(54);
	//
	// for (String field : str.split("\\|\\|")) {
	// String[] attributes = field.split(";;");
	// // determine type
	// String type = valueOf("type", attributes);
	// // Verify type
	// Type T = validType(type);
	// if (T == null) {
	// return false;
	// }
	// switch(T) {
	// case BREWERY:
	// createBrewery(attributes);
	// break;
	// case CHANCE:
	// createChance(/* attributes */);
	// break;
	// case JAIL:
	// createJail(attributes);
	// break;
	// case REFUGE:
	// createRefuge(attributes);
	// break;
	// case SHIPPING:
	// createShipping(attributes);
	// break;
	// case START:
	// createStart(attributes);
	// break;
	// case STREET:
	// createStreet(attributes);
	// break;
	// case TAX:
	// createTax(attributes);
	// break;
	// default:
	// break;
	// }
	// }
	// return true;
	// }
	//
	// private String readFile() {
	// BufferedReader in = null;
	// String str = "";
	// File file;
	// try {
	// if (path == null) {
	// InputStream is = getClass().getResourceAsStream("/fields.txt");
	// in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
	// } else {
	// file = new File(path);
	// in = new BufferedReader(new FileReader(file));
	// }
	//
	// String line;
	// while ((line = in.readLine()) != null) {
	// str += line.trim() + "\n";
	// }
	// } catch (FileNotFoundException ex) {
	// ex.printStackTrace();
	// return null;
	// } catch (IOException ex) {
	// ex.printStackTrace();
	// return null;
	// }
	// try {
	// in.close();
	// } catch (IOException ex) {
	// ex.printStackTrace();
	// return null;
	// }
	// return str;
	// }
	// private void createBrewery(String[] attributes) {
	// String picture = valueOf("picture", attributes);
	// String title = valueOf("title", attributes);
	// String subText = valueOf("subText", attributes);
	// String description = valueOf("description", attributes);
	// String leje = valueOf("leje", attributes);
	// Field f = new Brewery.Builder()
	// .setPicture(picture)
	// .setTitle(title)
	// .setSubText(subText)
	// .setDescription(description)
	// .setRent(leje)
	// .build();
	// fields.add(f);
	// }
	// private void createChance() {
	// Field f = new Chance.Builder().build();
	// fields.add(f);
	// }
	// private void createJail(String[] attributes) {
	// String picture = valueOf("picture", attributes);
	// String title = valueOf("title", attributes);
	// String subText = valueOf("subText", attributes);
	// String description = valueOf("description", attributes);
	// Field f = new Jail.Builder()
	// .setPicture(picture)
	// .setTitle(title)
	// .setSubText(subText)
	// .setDescription(description)
	// .build();
	// fields.add(f);
	// }
	// private void createRefuge(String[] attributes) {
	// String picture = valueOf("picture", attributes);
	// String title = valueOf("title", attributes);
	// String subText = valueOf("subText", attributes);
	// String description = valueOf("description", attributes);
	// Field f = new Refuge.Builder()
	// .setPicture(picture)
	// .setTitle(title)
	// .setSubText(subText)
	// .setDescription(description)
	// .build();
	// fields.add(f);
	// }
	// private void createShipping(String[] attributes) {
	// String picture = valueOf("picture", attributes);
	// String title = valueOf("title", attributes);
	// String subText = valueOf("subText", attributes);
	// String description = valueOf("description", attributes);
	// String leje = valueOf("leje", attributes);
	// Field f = new Shipping.Builder()
	// .setPicture(picture)
	// .setTitle(title)
	// .setSubText(subText)
	// .setDescription(description)
	// .setRent(leje)
	// .build();
	// fields.add(f);
	// }
	// private void createStart(String[] attributes) {
	// GUIColor bgColor = toColor(valueOf("backgroundColor", attributes));
	// GUIColor fgColor = toColor(valueOf("foregroundColor", attributes));
	// String title = valueOf("title", attributes);
	// String subText = valueOf("subText", attributes);
	// String description = valueOf("description", attributes);
	// Field f = new Start.Builder()
	// .setBgColor(bgColor)
	// .setFgColor(fgColor)
	// .setTitle(title)
	// .setSubText(subText)
	// .setDescription(description)
	// .build();
	// fields.add(f);
	// }
	// private void createStreet(String[] attributes) {
	// String title = valueOf("title", attributes);
	// GUIColor bgColor = toColor(valueOf("backgroundColor", attributes));
	// GUIColor fgColor = toColor(valueOf("foregroundColor", attributes));
	// String subText = valueOf("subText", attributes);
	// String description = valueOf("description", attributes);
	// String leje = valueOf("leje", attributes);
	// Field f = new Street.Builder()
	// .setTitle(title)
	// .setBgColor(bgColor)
	// .setFgColor(fgColor)
	// .setSubText(subText)
	// .setDescription(description)
	// .setRent(leje)
	// .build();
	// fields.add(f);
	// }
	// private void createTax(String[] attributes) {
	// String title = valueOf("title", attributes);
	// String subText = valueOf("subText", attributes);
	// String description = valueOf("description", attributes);
	// Field f = new Tax.Builder()
	// .setTitle(title)
	// .setSubText(subText)
	// .setDescription(description)
	// .build();
	// fields.add(f);
	// }
	// private Type validType(String type) {
	// for (Type t : Type.values()) {
	// if (t.toString().equalsIgnoreCase(type)) {
	// return t;
	// }
	// }
	// return null;
	// }
	// private String valueOf(String label, String[] attributes) {
	// for (String a : attributes) {
	// if (a.split("::")[0].trim().equalsIgnoreCase(label)) {
	// return a.split("::")[1];
	// }
	// }
	// System.err.println("GUI - Missing attribute: " + label);
	// return null;
	// }
	// private GUIColor toColor(String str) {
	// int r = Integer.parseInt(str.split(",,")[0]);
	// int g = Integer.parseInt(str.split(",,")[1]);
	// int b = Integer.parseInt(str.split(",,")[2]);
	// return new GUIColor(r, g, b);
	// }
}
